
#include "stdafx.h"
#include "vol_user_app_info.h"

CVolTables::CVolTables (CDatabase* pDatabase) : CRecordset(pDatabase)
{
    m_nFields = 5;
}

BOOL CVolTables::Open ()
{
    RETCODE nRetCode;

    // Cache state info and allocate hstmt
    SetState (0,NULL,noDirtyFieldCheck);
    if (!AllocHstmt())
        return FALSE;

    TRY
    {
        OnSetOptions(m_hstmt);
        AllocStatusArrays();

        // call the ODBC catalog function with data member params
        AFX_SQL_ASYNC(this, (::SQLTables)(m_hstmt,
            NULL, SQL_NTS,
            NULL, SQL_NTS,
            NULL, SQL_NTS,
            _T ("TABLE"), SQL_NTS));
        if (!Check(nRetCode))
            ThrowDBException(nRetCode, m_hstmt);

        // Allocate memory and cache info
        AllocAndCacheFieldInfo();
        AllocRowset();

        // Fetch the first row of data
        MoveNext();

        // If EOF, result set is empty, set BOF as well
        m_bBOF = m_bEOF;
    }
    CATCH_ALL(e)
    {
        Close();
        THROW_LAST();
    }
    END_CATCH_ALL

    return TRUE;
}

void CVolTables::DoFieldExchange (CFieldExchange* pFX)
{
    pFX->SetFieldType (CFieldExchange::outputColumn);
    RFX_Text(pFX, _T ("table_qualifier"), m_strQualifier);
    RFX_Text(pFX, _T ("table_owner"), m_strOwner);
    RFX_Text(pFX, _T ("table_name"), m_strName);
    RFX_Text(pFX, _T ("table_type"), m_strType);
    RFX_Text(pFX, _T ("remarks"), m_strRemarks);
}
